rm(list = ls())
library(tidyverse)
library(haven)
library(interflex)
## Heterogeneous Effect
subsidy_df = read_dta("~/Dropbox/revolving_door_jmp/replication_files/program_replication_jop.dta") 

# Figure E.1: Effect Heterogeneity in Different Subsamples ####
# Same figure as Figure 4, check code in Main_result/main_visualization


# Figure E.2: Conditional Effect of Market Development ####

out <- subsidy_df %>% 
  as.data.frame() %>% 
  filter(!is.na(mkt_index)) %>% 
  interflex(Y = "subsidy_l", D = "pre_hiring", X = "mkt_index",
            Z = c( "same_place","rd_offic"),
            estimator = "binning", FE = c("jurisdiction", "stkcd","year"),
            data =. ,na.rm = TRUE)

out_est <-interflex(Y = "Y", D = "D", X = "X", Z = c("Z1","Z2"), data = s5, estimator = "linear", diff.values = c(-2,0,2), vartype = "bootstrap")


plot(out,xlab = "Market Development", ylab = "Marginal Effect of Prehiring on Subsidy Value",  theme.bw = T)
ggsave( "~/Dropbox/Apps/Overleaf/subsidies_for_sale_2020/figure/marketization.png",height = 5,width = 7)
